package com.huike.web.controller.clues;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.dto.TbCluePageDto;
import com.huike.clues.domain.vo.AssignmentVo;
import com.huike.clues.service.TbClueService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "线索接口管理")
@RequestMapping("/clues/clue")
public class TbClueController extends BaseController {
    @Resource
    private TbClueService tbClueService;

    /**
     * 查询线索管理列表接口
     */
    @ApiOperation("查询线索管理列表接口")
    @GetMapping("/list")
    public TableDataInfo list(TbCluePageDto tbCluePageDto) {
        log.info("查询线索管理列表接口:{}", tbCluePageDto);
        startPage();
        List<TbClue> list = tbClueService.selectTbClueList(tbCluePageDto);
        return getDataTable(list);
    }

    /**
     * 查询线索池
     *
     * @param
     * @return
     */
    @ApiOperation("查询线索池")
    @GetMapping("/pool")
    public TableDataInfo pool(TbClue tbClue) {
        log.info("查询线索管理列表接口:{}", tbClue);
        startPage();
        List<TbClue> list = tbClueService.selectTbCluePool(tbClue);
        return getDataTable(list);
    }

    /**
     * 根据id获取线索基础信息
     */
    @ApiOperation("根据id获取线索基础信息接口")
    @GetMapping("/{id}")
    public AjaxResult selectCluesById(@PathVariable Long id) {
        log.info("根据id获取线索基础信息接口:{}", id);
        TbClue tbClue = tbClueService.selectCluesById(id);
        return new AjaxResult(200, "操作成功", tbClue);
    }

    /**
     * 新增线索管理
     */
    @ApiOperation("新增线索管理接口")
    @PostMapping
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addClues(@RequestBody TbClue tbClue) {
        log.info("新增线索管理接口:{}");
        if (!tbClueService.getPhone(tbClue.getPhone())) {
            return error("用户信息已存在");
        }
        tbClueService.addClues(tbClue);
        return AjaxResult.success("操作成功");
    }



}

